local extension = Package:new("lq__fhls")
extension.extensionName = "lq_reforge"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["lq__fhls"] = "风火林山",
}

-- 风-夏侯渊
local lq_refg__xiahouyuan = General:new(extension, "lq_refg__xiahouyuan", "wei", 3)
local lq__chongfeng = fk.CreateTriggerSkill{
  name = "lq__chongfeng",
  anim_type = "offensive",
  events = {fk.TurnStart, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
    player:usedSkillTimes(self.name, Player.HistoryTurn)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p) return p:inMyAttackRange(player) end)
    if #targets == 0 then return end
    local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#lq__chongfeng-invoke", self.name)
    if to[1] then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local slash = room:askForUseCard(to, "slash", nil, "#lq__chongfeng-slash:" .. player.id, true, { must_targets = {player.id}, bypass_times = true})
    if slash then
      room:useCard(slash)
    else
      if #room:askForDiscard(to, 2, 2, true, self.name, true, nil, "#lq__chongfeng-discard:" .. player.id) == 0 then
        room:damage{
          from = player,
          to = to,
          damage = 1,
          skillName = self.name
        }
      end
    end
  end,
}
lq_refg__xiahouyuan:addSkill(lq__chongfeng)
Fk:loadTranslationTable{
  ["lq_refg__xiahouyuan"] = "夏侯渊",
  ["#lq_refg__xiahouyuan"] = "力斩须臾",
  ["designer:lq_refg__xiahouyuan"] = "洛清",
  ["illustrator:lq_refg__xiahouyuan"] = "KayaK",

  ["lq__chongfeng"] = "冲锋",
  [":lq__chongfeng"] = "每回合限一次，回合开始时或你受到伤害后，你可以令一名攻击范围内有你的角色选择一项：1.对你使用一张【杀】；2.受到你造成的1点伤害；3.弃置两张牌。",
  ["#lq__chongfeng-invoke"] = "冲锋：你可以令一名攻击范围内有你的角色选择对你使用一张【杀】或受到减益",
  ["#lq__chongfeng-slash"] = "冲锋：你需对 %src 使用一张【杀】，否则你须弃两张牌或受到伤害",
  ["#lq__chongfeng-discard"] = "冲锋：你需弃置两张牌，否则 %src 对你造成1点伤害",

  ["$lq__chongfeng1"] = "吾善于千里袭人！",
  ["$lq__chongfeng2"] = "取汝首级，有如探囊取物！",
  ["~lq_refg__xiahouyuan"] = "竟然……比我还……快……",
}

-- 风-张郃（标张郃复制人）
local lq_refg__zhanghe = General(extension, "lq_refg__zhanghe", "wei", 4)
local lq__qiaobian = fk.CreateTriggerSkill{
  name = "lq__qiaobian",
  anim_type = "offensive",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isKongcheng() and
    data.to > Player.Start and data.to < Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, ".", "#lq__qiaobian-invoke:::" .. Util.PhaseStrMapper(data.to), true)
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
    player:skip(data.to)
    if data.to == Player.Draw then
      local targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
        return not p:isKongcheng() end), Util.IdMapper)
      if #targets > 0 then
        local n = math.min(2, #targets)
        local tos = room:askForChoosePlayers(player, targets, 1, n, "#lq__qiaobian-choose:::"..n, self.name, true)
        if #tos > 0 then
          room:sortPlayersByAction(tos)
          for _, id in ipairs(tos) do
            local p = room:getPlayerById(id)
            if not p:isKongcheng() then
              local card_id = room:askForCardChosen(player, p, "h", self.name)
              room:obtainCard(player, card_id, false, fk.ReasonPrey)
            end
          end
        end
      end
    elseif data.to == Player.Play then
      local targets = room:askForChooseToMoveCardInBoard(player, "#lq__qiaobian-move", self.name, true, nil)
      if #targets ~= 0 then
        targets = table.map(targets, function(id) return room:getPlayerById(id) end)
        room:askForMoveCardInBoard(player, targets[1], targets[2], self.name)
      end
    end
    return true
  end,
}
lq_refg__zhanghe:addSkill(lq__qiaobian)
Fk:loadTranslationTable{
  ["lq_refg__zhanghe"] = "张郃",
  ["#lq_refg__zhanghe"] = "料敌机先",
  ["designer:lq_refg__zhanghe"] = "洛清",
  ["illustrator:lq_refg__zhanghe"] = "张帅",

  ["lq__qiaobian"] = "巧变",
  [":lq__qiaobian"] = "你可以弃置一张手牌跳过一个阶段（准备阶段和结束阶段除外）。若以此法跳过摸牌阶段，"..
  "你可以获得至多两名其他角色的各一张手牌；若以此法跳过出牌阶段，你可以移动场上的一张牌。",
  ["#lq__qiaobian-invoke"] = "巧变：你可以弃一张手牌，跳过 %arg",
  ["#lq__qiaobian-choose"] = "巧变：你可以依次获得%arg名角色的各一张手牌",
  ["#lq__qiaobian-move"] = "巧变：请选择两名角色，移动场上的一张牌",

  ["$lq__qiaobian1"] = "兵无常势，水无常形。",
  ["$lq__qiaobian2"] = "用兵之道，变化万千。",
  ["~lq_refg__zhanghe"] = "啊……膝盖……中箭了……",
}

return extension